package com.ronghui.cash.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.ronghui.cash.entity.Invite;
import com.ronghui.cash.entity.User;
import com.ronghui.cash.mapper.UserMapper;
import com.ronghui.cash.service.InviteService;
import com.ronghui.cash.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 用户表 服务实现类
 * </p>
 *
 * @author wiki
 * @since 2017-12-02
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Autowired
    UserServiceImpl ronghuiUserService;

    @Autowired
    InviteService inviteService;

    @Autowired
    UserMapper userMapper;

    @Override
    public String checkUserExist(String username) {
        String result = "exist";
        User user = ronghuiUserService.selectOne(new EntityWrapper<User>().eq("username",username));
        if (user == null)
            result = "notExist";
        return result;
    }

    @Override
    public String checkNickname(String nickname) {
        String result = "exist";
        int i = ronghuiUserService.selectCount(new EntityWrapper<User>().eq("nickname",nickname));
        if (i == 0)
            result = "notExist";
        return result;
    }

    @Override
    public void register(User user, Invite invite) {
        if(invite != null){
            inviteService.insert(invite);
        }
        userMapper.insert(user);
    }
}
